<template>
	<view>
		<view class="addproject">
			<view class="" @click="toaddclass">
				新增分类
			</view>
			<view class="" @click="addproject">
				新增项目
			</view>
		</view>

		<scroll-view scroll-x="true" class="tab">
			<view class="tab_item scroll-view-item_H" v-for="(item,index) in classlist" :key="index"
				@click="selectclass(index)">
				<view class="img">
					<image :src="imageurl + item.image" mode=""></image>
				</view>
				<text :class="classindex==index?'active name':'name'">{{item.classifyName}}</text>
			</view>
		</scroll-view>
		<view class="list" v-for="(item,index) in shoplist" :key="index">
			<view class="list_item" @click="gotoStore(item)">
				<view class="img">
					<image :src="imageurl + item.image" mode=""></image>
				</view>
				<view class="list_content">
					<view class="boxs">
						<text class="shopName">{{item.classifyName}}</text>
						<text class="Grade">{{item.duration}}</text>
					</view>

					<text class="address">{{item.projectIntroduce}}</text>
				</view>
				<view class="distance">
					查看详情
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				classlist: [], //分类
				imageurl: this.$imgurl,
				classindex: 0, //分类下标
				page: 1,
				shoplist: [], //分类下的列表
			}
		},
		onLoad() {
			this.getclasslist()
		},
		onShow() {
			this.getclasslist()
		},
		methods: {
			//新增分类
			toaddclass(){
				uni.navigateTo({
					url:"../addclass/addclass"
				})
			},
			//获取分类下的列表
			getlist() {
				var that = this
				var data = {
					limit: 20,
					page: that.page,
				}
				that.$http('/api/user/store/list/' + 1 + '/' + that.classlist[that.classindex].id, 'GET', data).then((
					res) => {
						console.log('分类列表', res.data.data.list)
						that.shoplist = res.data.data.list
					})
			},
			//tab切换
			selectclass(index) {
				this.classindex = index
				this.getlist()
			},
			// 获取分类
			getclasslist() {
				var that = this
				var data = {}
				that.$http("/api/user/store/classifyList/" + 1, 'GET', data).then((res) => {
					console.log('分类', res.data.data.list)
					that.classlist = res.data.data.list
					that.getlist()
				})
			},
			//查看详情
			gotoStore(item) {
				var data = JSON.stringify(item)
				uni.navigateTo({
					url: "../projectdetails/projectdetails?data=" + data
				})
			},
			//新增项目
			addproject() {
				uni.navigateTo({
					url: "../addproject/addproject"
				})
			},
		}
	}
</script>

<style lang="scss">
	.addproject {
		display: flex;
		justify-content: space-between;

		view {
			width: 200rpx;
			height: 60rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			background-color: rgb(36, 153, 255);
			color: #FFFFFF;
			border-radius: 20rpx;
			float: right;
			margin: 20rpx;
		}
	}

	.tab {
		min-width: 750rpx;
		height: 250rpx;
		display: flex;
		border-bottom: 3px solid #eee;
		white-space: nowrap;

		.tab_item {
			width: 187.5rpx;
			height: 100%;
			display: inline-block;
			text-align: center;

			.name {
				padding: 4rpx 6rpx;
				border-radius: 50rpx;
				color: #f49c1c;
				border: 1rpx solid #f49c1c;
				font-size: 24rpx;
			}

			.active {
				background-color: #f49c1c;
				color: #FFFFFF;
			}

			.img {
				margin: 20rpx auto;

				width: 150rpx;
				height: 150rpx;

				image {
					border-radius: 50%;
					width: 100%;
					height: 100%;
				}
			}
		}
	}

	.list {
		border-bottom: 1rpx solid #ECECEC;

		.list_item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-top: 10rpx;
			padding: 20rpx 40rpx;
			font-size: 25rpx;
			box-sizing: border-box;

			.img {
				image {
					border-radius: 20rpx;
				}
			}

			.list_content {
				position: relative;
				display: flex;
				flex-direction: column;
				justify-content: center;
				line-height: 50rpx;
				width: 435rpx;

				.boxs {
					display: flex;
					align-items: center;

					.shopName {
						font-weight: bold;
						font-size: 30rpx;
					}

					.Grade {
						width: 80rpx;
						height: 30rpx;
						background-color: #f49c1c;
						color: #FFFFFF;
						margin-left: 10rpx;
						border-radius: 50rpx;
						font-size: 20rpx;
						display: flex;
						align-items: center;
						justify-content: center;
					}
				}


				.address {
					overflow: hidden;
					text-overflow: ellipsis;
					max-height: 434rpx;
					height: 91rpx;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					word-break: break-all;
					word-wrap: break-word;
					font-size: 24rpx;
					color: rgba(127, 127, 127, 0.9);
				}
			}

			.distance {
				margin-top: 105rpx;
				color: #C5C2C2;
			}

			.img {
				width: 120rpx;
				height: 120rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}
	}
</style>
